
package com.kugou.game.sdk.protocol;

import com.kugou.framework.http.RequestPackage;
import com.kugou.game.sdk.core.SDKControler;
import com.kugou.game.sdk.utils.AppUtil;

import android.content.Context;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Set;

/**
 * 抽象请求包
 * 
 * @author chenys
 */
public abstract class AbstractRequestPackage implements RequestPackage {

    protected HashMap<String, Object> mParams;

    @Override
    public String getGetRequestParams() {
        if (mParams != null && mParams.size() >= 0) {
            StringBuilder builder = new StringBuilder();
            builder.append("&");
            final Set<String> keys = mParams.keySet();
            for (String key : keys) {
                builder.append(key).append("=").append(mParams.get(key)).append("&");
            }
            builder.deleteCharAt(builder.length() - 1);
            return builder.toString();
        }
        return "";
    }

    public HashMap<String, Object> getParams() {
        return mParams;
    }

    public void setParams(HashMap<String, Object> mParams) {
        this.mParams = mParams;
    }

    @Override
    public Hashtable<String, String> getRequestHeaders() {
        Context context = SDKControler.getContext();
        Hashtable<String, String> headers = new Hashtable<String, String>();
        // imei
        headers.put("KYSDK-imei", AppUtil.getMachineSN(context));
        // mid
        headers.put("KYSDK-mid", AppUtil.getKugouMID(context));
        // uuid
        headers.put("KYSDK-uuid", AppUtil.getKugouUUID(context));
        // 游戏ID
        headers.put("KYSDK-gameId", SDKControler.getGameId() + "");
        // 游戏版本号
        headers.put("KYSDK-gameVerCode", AppUtil.getVersionCode(context) + "");
        // 游戏版本名称
        headers.put("KYSDK-gameVerName", AppUtil.getVersionName(context));
        // 渠道号
        headers.put("KYSDK-channelId", SDKControler.getChannelId() + "");
        int gameType = SDKControler.getGameType();
        // 游戏类型,1单机0网游
        headers.put("KYSDK-gametype", "" + gameType);
        // SDK版本
        headers.put("KYSDK-sdkVersion", "" + SDKControler.getSDKVersionCode());
        // 平台，1为android，2为ios官方版，3为ios越狱版
        headers.put("KYSDK-plat", "1");
        // 手机型号
        headers.put("KYSDK-model", AppUtil.getPhoneModel());
        // 网络类型，1=wifi，2=2g，3=3g，4=未知
        headers.put("KYSDK-nettype", "" + AppUtil.getNetworkType(context));
        return headers;
    }

    @Override
    public Hashtable<String, Object> getSettings() {
        return null;
    }
}
